package com.ruoyi.common.enums.business;


import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum SourceTypeEnum {
    NORMAL_REG(1, "普通注册"),
    KOC_EXCEL_IMPORT(2, "KOC用户导入");


    private final Integer code;
    private final String desc;

    private static final Map<Integer, SourceTypeEnum> ENUM_MAP;

    static {
        SourceTypeEnum[] values = values();
        Map<Integer, SourceTypeEnum> enToCn = new HashMap<>(values.length);
        for (SourceTypeEnum value : values) {
            enToCn.put(value.code, value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static SourceTypeEnum getEnumByCode(Integer code) {
        SourceTypeEnum sourceTypeEnum = ENUM_MAP.get(code);
        if (ObjectUtil.isEmpty(sourceTypeEnum)) {
            throw new RuntimeException("");
        }
        return sourceTypeEnum;
    }


}
